Reading from the Database
The process is very similar if you want to read from the Database.
Creating a Read Block
To add a new Read-Block, take a "mqtt-in" block from the Network section on the left and drag it into the Flow Creator tab. Then drag a "debug" block in as well.
In this example, the Database that is read from is MySQL and the Datasource is the "Datenquelle 1".
"ALL_DATATYPES" is the table you want to read from, which has to exist in the DB and be readable.
Configure the correct server for your Database by double-clicking the "mqtt-in" and set the action to "Subscribe to single topic".
The Topic has to be set to the topic of your Database, with the correct "r" Permission instead of "w", Datasource "Datenquelle 1" and table "ALL_DATATYPES".
The "debug"-node just has to have the Output set to "msg. payload". This node can also be the "mqtt-out" or the "function".
Then, after deploying this, the Debug tab on the right should give a message looking similar to this:
All Tags that are configured for the table "ALL_DATATYPES" in the right Datasource will be read out.
You could also use "ie/d/j/simatic/v1/mysc1/dp/r/Datenquelle 1/#" to read the messages from all tables of the datasource. In this case, the '#' functions like a wildcard.
Reading more Columns from the same table
If you want to read out another column, just add a new Tag in the Common Configurator, for example in the "ALL_DATATYPES" table to read out the "date" column:
Note that only one column per Table can have the "Sort by this column" checkbox enabled. Then re-deploy it to your Edge Device and go back to the Flow Creator. Nothing needs to be changed here and there should be a message like this in the Output.
In this case, the object at position 1 with the id "DP3" is the Datetime.
Reading Columns from another table
However, if you add another Tag from a different Table, both tables have to have one Tag set to "Sort by this column" as well. In this case, the column "value" in the table "READ_1". For this, the "READ_1" table has to exist, be online in the Database and be readable.
Create the Tag like the others above and make sure "Sort by this column" is set once per each table. Then re-deploy the Datasource to your Edge Device and go back to the Flow Creator. Create a new Read-Block like Creating a Read Block. The Topic of the "mqtt-in" block is the same, except instead of "ALL_DATATYPES" the table is "READ_1". Deploy it and there should be a message looking like this:
Further Information
To not make this documentation too long, only the most important points have been explained. For a full Configuration of the Database in the Common Configurator please refer to the Setup-Video in the Welcome Section. Use your own Database data and mqtt user with the correct permission. The rest of the documentation in more detail can be found under each DB kind of the SQL Connector.